<template>
    <div style="padding-left: 30%">

      <el-card class="box-card">

        <el-form :inline="false" :model="formInline" class="demo-form-inline" >
          <el-form-item label="账户：">
            <el-input v-model="formInline.userName" placeholder="请输入账户"></el-input>
          </el-form-item>
          <el-form-item label="密码：">
            <el-input type="password" v-model="formInline.password" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">登录</el-button>
          </el-form-item>
        </el-form>


      </el-card>

    </div>
</template>

<script>
    export default {
        name: "login.vue",
        data(){
          return{
            formInline:{
              userName:"",
              password:"",
            }
          }
        },
        methods:{
          onSubmit(){

              this.$axios.post(this.$serverInfo.serverapath+"login/toLogin",this.formInline).then((response)=>{

                 if(response.data.code==200){
                     //获取响应回来的用户信息
                     let userInfo=response.data.result;
                     //存储用户信息
                     window.localStorage.setItem("token",userInfo.token)
                     window.localStorage.setItem("userId",userInfo.userId)
                     window.localStorage.setItem("userName",userInfo.userName)
                     this.$router.push({path:"/index"})
                 }else{
                     this.$message({type:"error",message:response.data.msg})
                 }

              }).catch((error)=>{

              })

          }
        }
    }
</script>

<style>
  .box-card {
    width: 540px;
  }
</style>
